package com.tsd.wxpay.entity;

import com.alibaba.fastjson.JSON;
import com.github.binarywang.wxpay.bean.notify.WxPayOrderNotifyResult;
import com.github.binarywang.wxpay.bean.result.WxPayOrderQueryResult;
import com.tsd.core.utils.HlpUtils;
import io.swagger.annotations.ApiModel;

import java.io.Serializable;
import java.util.Date;

/**
 * 微信支付通知日志表扩展
 *
 * @author Hillpool
 * @date 2022/07/08 15:48:46
 */
@ApiModel(description = "微信支付通知日志表扩展")
public class WeixinPayNotifyLogExt extends WeixinPayNotifyLog implements Serializable {

    public WeixinPayNotifyLogExt() {
    }

    public WeixinPayNotifyLogExt(WxPayOrderNotifyResult result) {
        this.setOpen_id(result.getOpenid());
        this.setIs_subscribe(result.getIsSubscribe());
        this.setSub_is_subscribe(result.getSubIsSubscribe());
        this.setApp_id(result.getAppid());
        this.setSub_app_id(result.getSubAppId());
        this.setMch_id(result.getMchId());
        this.setSub_mch_id(result.getSubMchId());
        this.setOut_trade_no(result.getOutTradeNo());
        this.setTransaction_id(result.getTransactionId());
        this.setTrade_type(result.getTradeType());
        this.setBank_type(result.getBankType());
        this.setAttach(result.getAttach());
        this.setTotal_fee(result.getTotalFee());
        this.setFee_type(result.getFeeType());
        this.setCash_fee(result.getCashFee());
        this.setCash_fee_type(result.getCashFeeType());
        this.setSettlement_total_fee(result.getSettlementTotalFee());
        this.setCoupon_fee(result.getCouponFee());
        this.setCoupon_count(result.getCouponCount());
        if (!HlpUtils.isEmptyList(result.getCouponList())) {
            this.setCoupon_list_json(JSON.toJSONString(result.getCouponList()));
        }
        this.setPromotion_detail(result.getPromotionDetail());
        this.setTime_end(result.getTimeEnd());
        try {
            Date date = HlpUtils.string2Date(result.getTimeEnd(), HlpUtils.Format_YyyyMMddHHmmss);
            this.setPaid_date(date);
        } catch (Exception ignored) {
        }
        this.setRate_value(result.getRateValue());
        this.setNonce_str(result.getNonceStr());
        this.setSign_type(result.getSignType());
        this.setSign(result.getSign());
        this.setDevice_info(result.getDeviceInfo());
        this.setResult_code(result.getResultCode());
        this.setReturn_code(result.getReturnCode());
        this.setReturn_msg(result.getReturnMsg());
        this.setErr_code(result.getErrCode());
        this.setErr_code_des(result.getErrCodeDes());
        this.setHook_update(0);
    }

    public void update(WxPayOrderQueryResult result) {
        this.setReturn_code(result.getReturnCode());
        this.setReturn_msg(result.getReturnMsg());
        this.setResult_code(result.getResultCode());
        this.setErr_code(result.getErrCode());
        this.setErr_code_des(result.getErrCodeDes());
        this.setApp_id(result.getAppid());
        this.setSub_app_id(result.getSubAppId());
        this.setMch_id(result.getMchId());
        this.setSub_mch_id(result.getSubMchId());
        this.setNonce_str(result.getNonceStr());
        this.setSign(result.getSign());
        this.setPromotion_detail(result.getPromotionDetail());
        this.setDevice_info(result.getDeviceInfo());
        this.setOpen_id(result.getOpenid());
        this.setSub_open_id(result.getSubOpenid());
        this.setIs_subscribe(result.getIsSubscribe());
        this.setSub_is_subscribe(result.getIsSubscribeSub());
        this.setTrade_type(result.getTradeType());
        this.setTrade_state(result.getTradeState());
        this.setBank_type(result.getBankType());
        this.setTotal_fee(result.getTotalFee());
        this.setFee_type(result.getFeeType());
        this.setSettlement_total_fee(result.getSettlementTotalFee());
        this.setCash_fee(result.getCashFee());
        this.setCash_fee_type(result.getCashFeeType());
        this.setCoupon_fee(result.getCouponFee());
        this.setCoupon_count(result.getCouponCount());
        if (!HlpUtils.isEmptyList(result.getCoupons())) {
            this.setCoupon_list_json(JSON.toJSONString(result.getCoupons()));
        }
        this.setTransaction_id(result.getTransactionId());
        this.setOut_trade_no(result.getOutTradeNo());
        this.setAttach(result.getAttach());
        this.setTime_end(result.getTimeEnd());
        this.setTrade_state_desc(result.getTradeStateDesc());
    }
}